package com.atguigu.sparkcore.day01.singlevalue

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Author atguigu
 * Date 2020/10/27 14:37
 */
object GroupByDemo {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("GroupByDemo").setMaster("local[2]")
        val sc: SparkContext = new SparkContext(conf)
        val list1 = List(3, 50, 70, 6, 1, 20)
        val rdd1: RDD[Int] = sc.parallelize(list1, 2)
        val rdd2 = rdd1.groupBy(x => if (x % 2 == 0) "偶数" else "奇数")
        rdd2.collect().foreach(println)
        sc.stop()
        
    }
}
